//
//  MPBTools+addProperty.m
//  MPTToolsLibrary
//
//  Created by jiaxuzhou on 2017/7/20.
//  Copyright © 2017年 jxzjxz. All rights reserved.
//

#import "MPBTools+addProperty.h"
#import <objc/runtime.h>

@implementation MPBTools (addProperty)

+ (void)addCopyPropertyName:(NSString *)name value:(id)value onObj:(id)obj
{
    if (!name || !value || !obj)
    {
        return;
    }
    
    objc_setAssociatedObject(obj, (__bridge const void *)(name), value, OBJC_ASSOCIATION_COPY_NONATOMIC);

}

+ (void)addStrongPropertyName:(NSString *)name value:(id)value onObj:(id)obj
{
    if (!name || !value || !obj)
    {
        return;
    }
    
    objc_setAssociatedObject(obj, (__bridge const void *)(name), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

+ (void)addAssignPropertyName:(NSString *)name value:(id)value onObj:(id)obj
{
    if (!name || !value || !obj)
    {
        return;
    }
    
    objc_setAssociatedObject(obj, (__bridge const void *)(name), value, OBJC_ASSOCIATION_ASSIGN);
    
}

+ (id)getPropertyWithName:(NSString *)name onObj:(id)obj
{
    if (!name || !obj)
    {
        return nil;
    }
    
    id value = objc_getAssociatedObject(obj, (__bridge const void *)(name));
    
    return value;
}


@end
